﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using QuanLyBongDa.HeThongLuuTru;
using System.Windows.Forms;

namespace QuanLyBongDa.HeThongGiaoDien
{
    public partial class FormTraCuu : Form
    {
        public FormTraCuu()
        {
            InitializeComponent();
        }

        // biến trạng thái:
        int _trangthai;

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        public void HienThiKetQuaTimKiem()
        {
            string sql = null;
            if (_trangthai == 1)
            {
                // tra cứu cầu thủ:
                sql = "select * from DANHSACHCAUTHU where tencauthu like '%" + txtTuKhoa.Text.ToString() + "%'"; 
            }
            if (_trangthai == 2)
            {
                // tra cứu đội bóng:
                sql = "select * from DOIBONG where tendoibong like '%" + txtTuKhoa.Text.ToString() + "%'";
                
            }
            if (_trangthai == 3)
            {
                // tra cứu lịch thi đấu:
                sql = "select * from LICHTHIDAU where vongdau like '%" + txtTuKhoa.Text.ToString() + "%'";
            }
            if (_trangthai == 4)
            {
                // tra cứu kết quả thi đấu:
                sql = "select * from KETQUATHIDAU where matrandau like '%" + txtTuKhoa.Text.ToString() + "%'";
            }
            if (_trangthai == 5)
            {
                // tra cứu bảng xếp hạng:
                sql = "select * from BANGXEPHANG where ngay like '%" + txtTuKhoa.Text.ToString() + "%'";
            }
            if (_trangthai == 6)
            {
                // tra cứu hồ sơ đội bóng:
                sql = "select * from HOSODOIBONG where tendoibong like '%" + txtTuKhoa.Text.ToString() + "%'";
            }
            dgvTraCuu.DataSource = DataAccess.ExecQuery(sql);
        }


        private void btnTimKiem_Click(object sender, EventArgs e)
        {
            HienThiKetQuaTimKiem();
        }

        private void FormTraCuu_Load(object sender, EventArgs e)
        {

        }

        private void txtTuKhoa_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            txtTuKhoa.Text = "";
            txtTuKhoa.ForeColor = Color.Blue;
        }

        private void txtTuKhoa_Click(object sender, EventArgs e)
        {
            txtTuKhoa.Text = "";
            txtTuKhoa.ForeColor = Color.Blue;
        }

        private void cbbChon_SelectedIndexChanged(object sender, EventArgs e)
        {
            _trangthai = cbbChon.SelectedIndex + 1;
        }

        private void txtTuKhoa_TextChanged(object sender, EventArgs e)
        {
            if (!txtTuKhoa.Text.Equals(string.Empty))
            {
                HienThiKetQuaTimKiem();
            }
            
        }              
    }
}
